package uri.model.mypage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import uri.model.BoardVO;
import uri.model.DiaryVO;

@Service
public class MyPageServiceImpl implements MyPageService {
	@Resource(name="myPageDAOImpl")
	private MyPageDAO myPageDAO;

	@Override
	public ListVO diaryList(DiaryVO dvo) {
		if(dvo.getPage()==null||dvo.getPage()==""||dvo.getPage().equals("null")) 
			dvo.setPage("1");
		List<DiaryVO> list=myPageDAO.diaryList(dvo);
		int total=myPageDAO.totalContent(dvo.getId());
		PagingBean paging=new PagingBean(total,Integer.parseInt(dvo.getPage()));
		ListVO lvo=new ListVO(list,paging);
		return lvo;
	}

	@Override
	public void writeDiary(DiaryVO dvo) {
		myPageDAO.writeDiary(dvo);	
	}

	@Override
	public void deleteDiary(DiaryVO dvo) {
		myPageDAO.deleteDiary(dvo);	
	}

	@Override
	public DiaryVO updateDiaryForm(DiaryVO dvo) {
		return myPageDAO.updateDiaryForm(dvo);
	}

	@Override
	public void updateDiary(DiaryVO dvo) {
		//System.out.println(dvo+" @@@");
		myPageDAO.updateDiary(dvo);
	}

	@Override
	public ListVO searchDiaryByDate(DiaryVO dvo) {
		if(dvo.getPage()==null||dvo.getPage()==""||dvo.getPage()=="null") 
			dvo.setPage("1");
		List<DiaryVO> list=myPageDAO.searchDiaryByDate(dvo);
		int total=myPageDAO.searchTotalContent(dvo);
		PagingBean paging=new PagingBean(total,Integer.parseInt(dvo.getPage()));
		ListVO lvo=new ListVO(list,paging);
		return lvo;
	}

	@Override
	public void writeDiaryNoFile(DiaryVO dvo) {
		myPageDAO.writeDiaryNoFile(dvo);
		
	}

	@Override
	public void updateDiaryNoFile(DiaryVO dvo) {
		//System.out.println(dvo+" @@@ no file");
		myPageDAO.updateDiaryNoFile(dvo);
	}

	@Override
	public ListVO searchDiaryByContent(DiaryVO dvo) {
		if(dvo.getPage()==null||dvo.getPage()==""||dvo.getPage()=="null") 
			dvo.setPage("1");
		List<DiaryVO> list=myPageDAO.searchDiaryByContent(dvo);
		int total=myPageDAO.searchDiaryTotalContent(dvo);
		PagingBean paging=new PagingBean(total,Integer.parseInt(dvo.getPage()));
		ListVO lvo=new ListVO(list,paging);
		return lvo;
	}

	@Override
	public List<BoardVO> myListPub(BoardVO bvo) {
		return myPageDAO.myListPub(bvo);
		
	}
	@Override
	public List<BoardVO> myListCorr(BoardVO bvo) {
		return myPageDAO.myListCorr(bvo);
	}

	@Override
	public List<DiaryVO> myListDiary(DiaryVO dvo) {
		return myPageDAO.myListDiary(dvo);
	}

	@Override
	public Map searchTotal(String word) {
		Map<String,Object> map=new HashMap<String,Object>();
		List<DiaryVO> dlist=myPageDAO.searchDiaryByWord(word);
		if(dlist.size()==0){
			map.put("dinfo", "다이어리 검색결과 없음");
		}else{
			map.put("dlist",dlist);
			map.put("dword", word);
		}
		
		List<BoardVO> blist=myPageDAO.searchPublicByWord(word);
		if(blist.size()==0){
			map.put("binfo", "공유게시판 검색결과 없음");
		}else{
			map.put("blist",blist);
			map.put("bword", word);
		}
		
		List<BoardVO> clist=myPageDAO.searchCorrectionByWord(word);
		if(clist.size()==0){
			map.put("cinfo", "자기소개서 검색결과 없음");
		}else{
			map.put("clist",clist);
			map.put("cword", word);
		}
		return map;
	}

}
